package com.raymond.client.codec;

import com.raymond.client.codec.decoding.BaseDecoder;
import com.raymond.client.codec.encodeing.BaseEncoder;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 编解码策略
 *
 * @author :  raymond
 * @version :  V1.0
 * @date :  2021-07-15 09:11
 */
public class BraidedDecoder implements ICodec {
    private final Map<Integer, BaseDecoder> DECODER_MAP = new ConcurrentHashMap<>();

    public void putBaseDecoder(Integer commandId, BaseDecoder baseDecoder) {
        DECODER_MAP.put(commandId, baseDecoder);
    }

    @Override
    public BaseDecoder getBaseDecoder(int commandId) {
        return DECODER_MAP.get(commandId);
    }

    private final Map<Integer, BaseEncoder> ENCODER_MAP = new ConcurrentHashMap<>();

    public void putBaseEncoder(Integer commandId, BaseEncoder baseEncoder) {
        ENCODER_MAP.put(commandId, baseEncoder);
    }
    @Override
    public BaseEncoder getBaseEncoder(int commandId) {
        return ENCODER_MAP.get(commandId);
    }


}
